#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::endl;
using std::set;
using std::vector;
using std::pair;
using std::max;

void read(int &n, vector <int> &t, vector <vector <int> > &g) {
	cin >> n;
	t.resize(n + 1);
	g.resize(n + 1);
	for (int i = 1; i <= n; ++i) {
		cin >> t[i];
		if (t[i] == 0) {
			g[0].push_back(i);
		}
		int sz;
		cin >> sz;
		g[i].resize(sz);
		for (int j = 0; j < sz; ++j) {
			cin >> g[i][j];
		}
	}
}

const int INF = (int)1e9;

void dfs(int v, vector <vector <int> > &g, vector <int> &t, int T, vector <bool> &u, int &cnt) {
    ++cnt;
    u[v] = 1;
    for (auto to: g[v]) {
        if (!u[to] && t[to] <= T) {
            dfs(to, g, t, T, u, cnt);
        }
    }
}

int solve(int n, vector <int> &t, vector <vector <int> > &g) {
    int c = -1;
    vector <bool> u(n + 1);
    dfs(0, g, t, INF, u, c);
    if (c < (n + 1) / 2) {
        return -1;
    }
    int L = 0, R = INF;
    while (L < R) {
        int M = (L + R) / 2;
        u.assign(n + 1, 0);
        c = -1;
        dfs(0, g, t, M, u, c);
        if (c < (n + 1) / 2) {
            L = M + 1;
        }
        else {
            R = M;
        }
    }
    return L;
}

int main() {
    //freopen("input.txt", "r", stdin);
	int n;
	vector <int> t;
	vector <vector <int> > g;
	read(n, t, g);
	cout << solve(n, t, g) << endl;
}
